//
//  AIGirlLoginAwardView.swift
//  AIGirl
//
//  Created by Rae on 2024/1/17.
//

import UIKit
import SwiftEntryKit

class AIGirlLoginAwardView: UIView, AnimationProtocol, AnimationDelegate {

    func animationContainerViewSize() -> CGSize {
        CGSize(width: .screenWidth, height: 450.0)
    }
    
    func animationContainerViewStyle() -> AnimationViewStyle {
        .center
    }
    
    func animationContainerScreenInteraction() -> EKAttributes.UserInteraction {
        .init()
    }
    
    private let bgImageView = c_make_ex(UIImageView.self)
        .mode(.scaleAspectFill).image("AIGirl_Home_Award_bg").end()
    private lazy var moneyLabel = c_make_ex(UILabel.self)
        .color("#FFD800").font(30.font_blackItalic).alignment(.right).end()
    private lazy var contentLabel = c_make_ex(UILabel.self)
        .color(.white).font(18.font_blackItalic).alignment(.center).line(0)
        .text("Welcome to join, we have prepared some gold coins for you. Hope you find love here.").end()
    private lazy var collectButton = c_make_ex(UIButton.self)
        .image("AIGirl_Home_Award_collect").end()
    private lazy var closeButton = c_make_ex(UIButton.self)
        .image("AIGirl_Home_Award_close").end()
    
    var value: Int = 0 {
        didSet{
            moneyLabel.text = "X " + String(value)
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        subviews{
            bgImageView.subviews{
                moneyLabel
                contentLabel
                collectButton
            }
            closeButton
        }
        
        bgImageView.leading(0).top(25).trailing(0).height(345)
        moneyLabel.trailing(90).top(125)
        collectButton.leading(37.5).trailing(37.5).height(50).bottom(20)
        contentLabel.leading(32).trailing(32)
        contentLabel.Bottom == collectButton.Top - 20
        closeButton.size(45).centerHorizontally()
        closeButton.Top == bgImageView.Bottom + 25
        closeButton.addTarget(self, action: #selector(clickCloseButton), for: .touchUpInside)
        collectButton.isUserInteractionEnabled = false
        let tap = UITapGestureRecognizer(target: self, action: #selector(clickDismissBtn))
        bgImageView.isUserInteractionEnabled = true
        bgImageView.addGestureRecognizer(tap)
    }
    
    @objc private func clickCloseButton(){
        
        self.animation.animation(dismiss: self)
    }
    
    @objc private func clickDismissBtn(){
        GlobalTool.refreshUserInfo { [weak self] in
            NotificationCenter.default.post(name: .userBalanceChanged, object: nil)
            self?.animation.animation(dismiss: self)
        }
//        GlobalTool.userModel?.money = (GlobalTool.userModel?.money ?? 0) + value
       
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}

class AIGirlLoginDailyAwardView: UIView, AnimationProtocol, AnimationDelegate {

    func animationContainerViewSize() -> CGSize {
        CGSize(width: .screenWidth, height: 450)
    }
    
    func animationContainerViewStyle() -> AnimationViewStyle {
        .center
    }
    
    func animationContainerScreenInteraction() -> EKAttributes.UserInteraction {
        .init()
    }
    
    private let bgImageView = c_make_ex(UIImageView.self)
        .mode(.scaleAspectFill).image("AIGirl_Home_Award_DailyBg").end()
    private lazy var moneyLabel = c_make_ex(UILabel.self)
        .color("#FFD800").font(30.font_blackItalic).alignment(.right).end()
    private lazy var closeButton = c_make_ex(UIButton.self)
        .image("AIGirl_Home_Award_close").end()
    
    var value: Int = 0 {
        didSet{
            moneyLabel.text = "X " + String(value)
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        subviews{
            bgImageView.subviews{
                moneyLabel
            }
            closeButton
        }
        
        bgImageView.leading(0).top(25).trailing(0).height(345)
        moneyLabel.trailing(90).top(125)
        closeButton.size(45).centerHorizontally()
        closeButton.Top == bgImageView.Bottom + 25
        closeButton.addTarget(self, action: #selector(clickCloseButton), for: .touchUpInside)
        let tap = UITapGestureRecognizer(target: self, action: #selector(clickDismissBtn))
        bgImageView.isUserInteractionEnabled = true
        bgImageView.addGestureRecognizer(tap)
    }
    
    @objc private func clickCloseButton(){
        
        self.animation.animation(dismiss: self)
    }
    
    @objc private func clickDismissBtn(){
        
        self.animation.animation(dismiss: self)
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}


class AIGirlBanView: UIView, AnimationProtocol, AnimationDelegate {

    func animationContainerViewSize() -> CGSize {
        CGSize(width: .screenWidth, height: 235.0)
    }
    
    func animationContainerViewStyle() -> AnimationViewStyle {
        .center
    }
    
    func animationContainerScreenInteraction() -> EKAttributes.UserInteraction {
        .init()
    }
    
    private let bgView = c_make_ex(UIView.self)
        .bgColor(.black).corner(25).end()
    private lazy var iconImageView = c_make_ex(UIImageView.self)
        .image("AIGirl_Ban").end()
    private lazy var contentLabel = c_make_ex(UILabel.self)
        .color("#FF2B69").font(20.font_semiBold).alignment(.center).line(0)
        .text("sorry. Please do not record or take screenshots.").end()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        subviews{
            bgView.subviews{
                iconImageView
                contentLabel
            }
        }
        
        bgView.leading(15).top(0).trailing(15).bottom(0)
        iconImageView.size(70).top(30).centerHorizontally()
        contentLabel.leading(20).trailing(20)
        contentLabel.Top == iconImageView.Bottom + 30
    }
    
    @objc private func clickCloseButton(){
        
        self.animation.animation(dismiss: self)
    }
    
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}
